COMP30760 Data Science in Python Assignment -2

SURABHI AGARWAL - 17203535

The Stocks Selected:

  • Apple (APPL)
  • Alphabet Inc. (GOOG)
  • Disney (DIS)
  • Microsoft (MSFT)
In [1]:
import pandas as pd
from pandas import Series
import urllib.request
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.graph_objects as go

Apple

  • Stock analysis for the company apple

Task 1: Data Collection

  • Using python, I downloaded the HTML pages for my chosen stocks
In [2]:
#Defining a method called get_raw_data which requests data from the given html link for the company passed as parameter
def get_raw_data(company):
    url = "http://mlg.ucd.ie/modules/COMP30760/stocks/"+company+".html"
    try:
        response = urllib.request.urlopen(url)
        text = response.read().decode()
    except:
        print("Failed to retrieve %s" % url)
    

Task 2 : Data Preparation

Parsing data:

  • Using pandas libray, I parsed and extracted the data for the company APPLE and represented the whole dataset as a dataframe
  • Handling missing values
  • Saving and exporting the data into csv format
In [3]:
#calling the method get_raw_data to get data for the company APPLE
get_raw_data("aapl")
#Creating Apple dataframe and concatenting all the columns into one dataframe
apple_df = pd.read_html("http://mlg.ucd.ie/modules/COMP30760/stocks/aapl.html")
apple_df = pd.concat(apple_df)
#Displaying the dataframe
apple_df
    
Out[3]:
Stock Year Month Day Open High Low Close
0 AAPL 2012 1 3 58.485714 58.928570 58.428570 58.747143
1 AAPL 2012 1 4 58.571430 59.240002 58.468571 59.062859
2 AAPL 2012 1 5 59.278572 59.792858 58.952858 59.718571
3 AAPL 2012 1 6 59.967144 60.392857 59.888573 60.342857
4 AAPL 2012 1 9 60.785713 61.107143 60.192856 60.247143
5 AAPL 2012 1 10 60.844284 60.857143 60.214287 60.462856
6 AAPL 2012 1 11 60.382858 60.407143 59.901428 60.364285
7 AAPL 2012 1 12 60.325714 60.414288 59.821430 60.198570
8 AAPL 2012 1 13 59.957142 60.064285 59.808571 59.972858
9 AAPL 2012 1 17 60.599998 60.855713 60.422855 60.671429
10 AAPL 2012 1 18 60.994286 61.352856 60.900002 61.301430
11 AAPL 2012 1 19 61.450001 61.624287 60.930000 61.107143
12 AAPL 2012 1 20 61.070000 61.071430 59.964287 60.042858
13 AAPL 2012 1 23 60.381428 61.207142 60.328571 61.058571
14 AAPL 2012 1 24 60.728573 60.728573 59.935715 60.058571
15 AAPL 2012 1 25 64.919998 64.921425 63.389999 NaN
16 AAPL 2012 1 26 64.051430 64.112854 63.305714 63.518570
17 AAPL 2012 1 27 63.477142 64.068573 63.395714 63.897144
18 AAPL 2012 1 30 63.672855 64.842857 63.627144 64.715714
19 AAPL 2012 1 31 65.084282 65.462860 64.724289 65.211426
20 AAPL 2012 2 1 65.487144 65.570000 65.078575 65.169998
21 AAPL 2012 2 2 65.128571 65.309998 64.854286 NaN
22 AAPL 2012 2 3 65.328575 65.714287 65.080002 65.668571
23 AAPL 2012 2 6 65.482857 66.425713 65.457146 66.281425
24 AAPL 2012 2 7 66.464287 67.107140 66.368568 66.975716
25 AAPL 2012 2 8 67.214287 68.112854 67.099998 68.097145
26 AAPL 2012 2 9 68.680000 70.964287 68.651428 70.452858
27 AAPL 2012 2 10 70.137146 71.088570 69.792854 70.488571
28 AAPL 2012 2 13 71.361427 71.975716 71.012856 71.800003
29 AAPL 2012 2 14 72.094284 72.794289 71.714287 72.779999
... ... ... ... ... ... ... ... ...
181 AAPL 2019 9 20 221.380005 222.559998 217.470001 217.729996
182 AAPL 2019 9 23 218.949997 219.839996 217.649994 218.720001
183 AAPL 2019 9 24 221.029999 222.490005 217.190002 217.679993
184 AAPL 2019 9 25 218.550003 221.500000 217.139999 221.029999
185 AAPL 2019 9 26 220.000000 220.940002 218.830002 219.889999
186 AAPL 2019 9 27 220.539993 220.960007 217.279999 218.820007
187 AAPL 2019 9 30 220.899994 224.580002 220.789993 223.970001
188 AAPL 2019 10 1 225.070007 228.220001 224.199997 224.589996
189 AAPL 2019 10 2 223.059998 223.580002 217.929993 NaN
190 AAPL 2019 10 3 218.429993 220.960007 215.130005 220.820007
191 AAPL 2019 10 4 225.639999 227.490005 223.889999 227.009995
192 AAPL 2019 10 7 226.270004 229.929993 225.839996 227.059998
193 AAPL 2019 10 8 225.820007 228.059998 224.330002 224.399994
194 AAPL 2019 10 9 227.029999 227.789993 225.639999 227.029999
195 AAPL 2019 10 10 227.929993 230.440002 227.300003 230.089996
196 AAPL 2019 10 11 232.949997 237.639999 232.309998 236.210007
197 AAPL 2019 10 14 234.899994 238.130005 234.669998 235.869995
198 AAPL 2019 10 15 236.389999 237.649994 234.880005 235.320007
199 AAPL 2019 10 16 233.369995 235.240005 233.199997 234.369995
200 AAPL 2019 10 17 235.089996 236.149994 233.520004 235.279999
201 AAPL 2019 10 18 234.589996 237.580002 234.289993 236.410004
202 AAPL 2019 10 21 237.520004 240.990005 237.320007 240.509995
203 AAPL 2019 10 22 241.160004 242.199997 239.619995 239.960007
204 AAPL 2019 10 23 242.100006 243.240005 241.220001 243.179993
205 AAPL 2019 10 24 244.509995 244.800003 241.809998 243.580002
206 AAPL 2019 10 25 243.160004 246.729996 242.880005 246.580002
207 AAPL 2019 10 28 247.419998 249.250000 246.720001 249.050003
208 AAPL 2019 10 29 248.970001 249.750000 242.570007 243.289993
209 AAPL 2019 10 30 244.759995 245.300003 241.210007 243.259995
210 AAPL 2019 10 31 247.240005 249.169998 237.259995 248.759995

1971 rows × 8 columns

Representing data as time series:

  • To represent data as time series, first I would combine the year, month and day column of the data frame
  • Use the date column as the index of the data frame
  • Display the dataframe
In [4]:
#representing data as time series
apple_df['Date'] = pd.to_datetime(apple_df[['Year', 'Month', 'Day']])
#setting the data column as index
apple_df.set_index('Date', inplace =True)
apple_df.head()
Out[4]:
Stock Year Month Day Open High Low Close
Date
2012-01-03 AAPL 2012 1 3 58.485714 58.928570 58.428570 58.747143
2012-01-04 AAPL 2012 1 4 58.571430 59.240002 58.468571 59.062859
2012-01-05 AAPL 2012 1 5 59.278572 59.792858 58.952858 59.718571
2012-01-06 AAPL 2012 1 6 59.967144 60.392857 59.888573 60.342857
2012-01-09 AAPL 2012 1 9 60.785713 61.107143 60.192856 60.247143

Exporting data to an appropriate format:

  • Exporting the raw data into csv file with date column
In [5]:
#Exporting the data to csv file
apple_df.to_csv("Apple Stock.csv", index=True, encoding='utf8')
In [6]:
#Dropping the the unnecessary columns
apple_df = apple_df.drop(["Stock", "Year", "Month", "Day"], axis=1)
#Diplaying the data frame
apple_df.head()
Out[6]:
Open High Low Close
Date
2012-01-03 58.485714 58.928570 58.428570 58.747143
2012-01-04 58.571430 59.240002 58.468571 59.062859
2012-01-05 59.278572 59.792858 58.952858 59.718571
2012-01-06 59.967144 60.392857 59.888573 60.342857
2012-01-09 60.785713 61.107143 60.192856 60.247143

Handling missing values:

  • Using interpolate method in the pandas library, I filled in the missing values in the dataframe
In [7]:
#Using df.interpolate, we can fill in the missing values in the dataframe
apple_df = apple_df.interpolate()
#Check if there are still any missing values left
apple_df.isnull().sum()
Out[7]:
Open     0
High     0
Low      0
Close    0
dtype: int64
In [8]:
#Rounding off the stock figures to make sure there is consistency in the data 
apple_df = apple_df.round(2)
apple_df.head()
Out[8]:
Open High Low Close
Date
2012-01-03 58.49 58.93 58.43 58.75
2012-01-04 58.57 59.24 58.47 59.06
2012-01-05 59.28 59.79 58.95 59.72
2012-01-06 59.97 60.39 59.89 60.34
2012-01-09 60.79 61.11 60.19 60.25

Pre processing completed:

  • The data contains no null values i.e there are no values in the dataset such as "Not Available", "NaN or "NA"
  • All the values are not strings either
  • This indicates that there all the values are present in the dataset.

Task 3.1: Data Analysis: Summarising the cleaned dataset

Descriptive Statistics:

  • Displaying the descriptive statistics of the dataset
  • Using the cleaned dataset for further analysis and visualization
  • Grouping the data by year and taking mean of the values and displaying descriptive statistics

Calculating mean of stocks for each year:

  • This helps us understand net stock price for each year for easier visualization.
In [9]:
#Finding mean for each of the open, high, low and closing values of the stocks for each year
apple_df_year = apple_df.groupby(apple_df.index.year).mean().round(2)
#Displaying the most recent years that is the ending rows of the dataframe
apple_df_year.tail()
Out[9]:
Open High Low Close
Date
2015 120.18 121.25 118.87 120.05
2016 104.51 105.43 103.70 104.63
2017 150.47 151.42 149.49 150.52
2018 189.08 191.00 187.18 189.06
2019 196.04 197.96 194.42 196.28
  • Above shown is the mean of all the stock prices(open, high, low, close) of Apple grouped by Year.
  • We can see that the Average Stock Prices go up every year.
  • We can also notice that there has been quite a huge increase in stock prices per share from mean value of 120 dollars per share in 2015 to 196 dollars per share in 2019.
In [10]:
#Using the pandas dataframe and the decribe method we can see the descriptive statistics
print("Apple Stock Descriptive Stats:")
apple_df.describe().round(2)
Apple Stock Descriptive Stats:
Out[10]:
Open High Low Close
count 1971.00 1971.00 1971.00 1971.00
mean 123.84 124.94 122.72 123.85
std 46.72 47.16 46.36 46.77
min 55.42 57.09 55.01 55.79
25% 85.40 86.06 84.34 85.29
50% 112.21 113.25 111.23 112.18
75% 160.00 161.21 158.62 159.88
max 248.97 249.75 246.72 249.05
  • The above tables gives us the descriptive statistics of Apple stock market showing different statistics like mean, standard deviation, minimum and maximum values.
  • As we can notice that the mean prices of Apple stock has been around 123 dollars per share and the maximum value of the stock price has been 249 dollars per share.

Task 3.2: Data Analysis: Data Visualization

Characterising and Visualizing time series:

  • Using matplotlib, I visualized the time series in order to gain characterisitic insights on daily, monthly, quarterly and annual frequencies.
  • Discussing how each time series is changing over time
In [11]:
#Plotting visualization of time series to see change rate of stock price annually
apple_df["2012":"2019"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2)
#Naming the plot
plt.title('Apple Stock Price (Annual Frequency)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the annual trend of stock prices for the company Apple from the year 2012-2019.
  • We notice that the overall trend of the closing stock prices is increasing
  • However, it is interesting to notice the dip in the low stock prices in the middle of 2015 and also towards the end of each year and a strict rise from 2017 onwards.
  • It is also interesting to notice the fall in stock prices nearing the end of 2018 followed by a sudden increase following the year 2019.
  • Let us visualize the 2018-19 in terms of a monthly frequency to gain more insights.
In [12]:
#Plotting visualizations of time series to see change rate of stock price monthly
apple_df["2018-01":"2019-04"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2)
#Naming the plot
plt.title('Apple Stock Price (Monthly Frequency)')
#Labelling the axis
plt.xlabel("Month",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the monthly trend of stock prices for the company Apple from March 2018 to March 2019
  • We notice that the overall trend of the closing stock prices is seasonal affected by the chosen time period. We can see rise and falls in particular months.
  • We can see that from July 2018 there has been a steep rise in the stock prices and following the end of 2018, there has been a decreasing trend.
  • Following January 2019, there has been a strict increase
  • Let us visualize the quarter from December 2018 to February 2019 in terms of a quarterly frequency to gain more insights.
In [13]:
#Plotting visualization of time series to see change rate of stock price quarterly
apple_df["2018-12":"2019-02"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 3)
#Naming the plot
plt.title('Apple Stock Price (Quarterly Frequency)')
#Labelling the axis
plt.xlabel("Quarter",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the quaterly trend of stock prices for the company Apple from December 2018 to February 2019
  • We notice that the trend of the prices have been drecreasing for the first half of the quarter and increasing after January 2019.
  • The interesting part is the sudden fall in the prices in the first few days of January 2019 and an increase following those dates.
  • The trend following February 2019 has been more or less constant.
  • Let us visualize the daily frequency from January 2019 to February 2019 to gain more insights.
In [14]:
#Plotting visualization of time series to see change rate of stock price daily
apple_df["2019-01-01":"2019-02-01"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 3)
#Naming the plot
plt.title('Apple Stock Price (Daily Frequency)')
#Labelling the axis
plt.xlabel("Day",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the daily trend of stock prices for the company Apple from January 2019 to February 2019
  • We notice that overall that has been an increasing trend for the stock prices for each day of the month.
  • We can even notice several breaking points such as peaks and lows in a triangular increase fashion and a peak on the 29th of January.

Task 3.3: Quantifying and Discussing the time series

Discussing the changes in time series:

  • Using matplotlib, I used different graphs like bar graphs and rolling mean line graphs, I discussed the plots in details to get more insights.
In [15]:
#Plotting bar graph visualization of time series to see change rate of stock price annually
apple_df_year.plot(kind = 'bar', figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, stacked = False, zorder=3)
#Naming the plot
plt.title('Apple Stock Price (Annual bar chart)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows that overall there has been a huge increase in the stock prices of Apple from 80 dollars per share in the year 2012 to 195 dollars per share in the year 2019.
In [16]:
#Calculating 30 year rolling mean of APPLE stock prices
rm = apple_df["Close"].rolling(30).mean()
p = rm.plot(figsize=(16, 5), fontsize=13, grid = True, color= 'red', linewidth = 3)
#Naming the plot
plt.title('Apple Stock Price (Rolling mean of 30 years)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13)
Out[16]:
Text(0, 0.5, 'Price($)')
  • The above plot shows the rolling mean line graph for the company Apple.
  • Rolling means (or moving averages) are generally used to smooth out short-term fluctuations in time series data and highlight long-term trends.
  • We are now able to see a visualization which is without any noise.
  • Clearly we can notice that there was a huge fall in stock prices of Apple nearing 2019 which I would be discussing in detail in my outlying observations.

Task 3.4: Outlying observations & Final conclusions

Observations:

  • Through a candlestick plot made using plotly library, I discussed all the outlying observations throughout the changes in the time series.
In [17]:
#Using plotly library, plotting a candlestick plot to discuss the increasing and decreasing points of the stock prices
fig = go.Figure(data=[go.Candlestick(x=apple_df.index,
                open=apple_df['Open'],
                high=apple_df['High'],
                low=apple_df['Low'],
                close=apple_df['Close'], increasing_line_color= 'cyan', decreasing_line_color= 'grey')])
fig.update_layout(
    #naming the plot
    title='Apple Stock Price',
    #labelling the axis
    yaxis_title='Price($)',
    xaxis_title='Year',
    shapes = [dict(
        #labelling the increasing period line
        x0='2016-12-09', x1='2016-12-09', y0=0, y1=1, xref='x', yref='paper',
        line_width=2)],
    annotations=[dict(
        x='2016-12-09', y=0.05, xref='x', yref='paper',
        showarrow=False, xanchor='left', text='Increase Period Begins')]
)
fig.show()

12% Fall in Apple stocks in December 2018

  • We notice that there was a strict increase in the Apple stock price following 2017, however a huge dip was noticed in December 2018.
  • The stock ended trading at 142.12 dollars per share in the year 2018 which has been quite low since 2017.
  • According to CNBC, there had been a lot of concern about how China-U.S. trade relations might impact iPhone sales. On top of that, in early December, a Chinese court ordered Apple to halt sales of older iPhone models. China accounted for about a fifth of Apple's total revenue in fiscal 2018 (which ended in September).
  • At least a few analysts have cut their price targets on Apple over the last month, which can affect the stock's performance in the short term
  • Now the iPhone maker has also been infected by the market fears, of which there are plenty, including overly optimistic valuations, rising interest rates, currency fluctuation and US-China trade tensions.

A Huge Increase in 2019

  • However, an analyst predicted that Apple's stock could increase upto 13% in 2019 which has proven to be right.
  • Apple shares have made a strong comeback in 2019. After falling more than 8% in 2018, the stock has risen close to 40% YTD (year-to-date).
  • The iPhone11 continues to account for close to 50% of the company’s total sales. Apple will be banking on growing iPhone demand from China. Nearly 70 million customers in China are due for an upgrade. -Apple hasn’t increased the price of its new iPhones. In fact, the iPhone 11 is priced at 699 dollars, while the Pro and Max are available starting at 999 dollars and 1090 dollars, respectively. The iPhone 11 will be a key revenue driver for the next 12–18 months.
  • Finally, there's Apple's fast-growing wearables business. Its wearables products -- Apple Watch, AirPods, and Beats earphones -- have taken off.
  • It is predicted that Apple stock could close on 300 dollars per share in 2019 and have estimated to be in good shape even in the coming year of 2020.

Alphabet Inc.

  • Stock analysis for the company Alphabet Inc. [Parent company of Google]

Task 1: Data Collection

  • Using python, I downloaded the HTML pages for my chosen stocks
In [18]:
#calling the method get_raw_data to download data for the company Alphabet Inc
get_raw_data("goog")

Task 2.1: Data Preparation: Parsing and extracting data

Parsing data:

  • Using pandas libray, I parsed and extracted the data for the company Alphabet Inc. and represented the whole dataset as a dataframe
In [19]:
#Creating the Alphabet dataframe and concatenting all the columns into one dataframe
google_df = pd.read_html("http://mlg.ucd.ie/modules/COMP30760/stocks/goog.html")
google_df = pd.concat(google_df)
#Displaying the dataframe
google_df
    
Out[19]:
Stock Year Month Day Open High Low Close
0 GOOG 2012 1 3 325.250885 332.827484 324.966949 331.462585
1 GOOG 2012 1 4 331.273315 333.873566 329.076538 332.892242
2 GOOG 2012 1 5 329.828735 330.745300 326.889740 328.274536
3 GOOG 2012 1 6 NaN NaN NaN NaN
4 GOOG 2012 1 9 322.042908 322.291962 309.455078 310.067780
5 GOOG 2012 1 10 313.699188 315.716614 307.303162 310.406525
6 GOOG 2012 1 11 310.585846 313.519836 309.400299 311.811249
7 GOOG 2012 1 12 314.431427 315.263306 312.080261 313.644379
8 GOOG 2012 1 13 311.960693 312.304413 309.370392 311.328064
9 GOOG 2012 1 17 314.810028 314.810028 311.671783 313.116364
10 GOOG 2012 1 18 312.144989 315.816254 309.898438 315.273285
11 GOOG 2012 1 19 319.298187 319.298187 314.550995 NaN
12 GOOG 2012 1 20 294.162415 294.396515 289.763885 291.900879
13 GOOG 2012 1 23 291.905853 293.230896 290.491180 291.666748
14 GOOG 2012 1 24 292.065277 292.742737 287.920807 289.380341
15 GOOG 2012 1 25 287.676727 288.274475 282.132507 283.681702
16 GOOG 2012 1 26 284.922028 286.167389 281.220917 NaN
17 GOOG 2012 1 27 284.324280 289.076477 283.601990 NaN
18 GOOG 2012 1 30 287.945709 288.917053 285.629395 287.766388
19 GOOG 2012 1 31 290.411469 290.909607 286.501129 288.971863
20 GOOG 2012 2 1 291.377838 291.656799 288.488678 289.330505
21 GOOG 2012 2 2 291.342987 292.110107 289.953186 291.462524
22 GOOG 2012 2 3 294.227173 297.420197 292.927032 297.051575
23 GOOG 2012 2 6 296.394043 304.274506 295.895905 303.407745
24 GOOG 2012 2 7 302.441376 303.557190 300.752716 302.252075
25 GOOG 2012 2 8 303.183594 304.533539 301.240875 303.786346
26 GOOG 2012 2 9 304.867279 306.102661 303.362915 NaN
27 GOOG 2012 2 10 302.805023 302.929535 300.872253 301.823700
28 GOOG 2012 2 13 304.110107 305.773895 303.871002 304.956940
29 GOOG 2012 2 14 304.628174 304.857330 301.250824 303.741516
... ... ... ... ... ... ... ... ...
181 GOOG 2019 9 20 1233.119995 1243.319946 1223.079956 1229.930054
182 GOOG 2019 9 23 1226.000000 1239.089966 1224.170044 1234.030029
183 GOOG 2019 9 24 1240.000000 1246.739990 1210.680054 1218.760010
184 GOOG 2019 9 25 1215.819946 1248.300049 1210.089966 1246.520020
185 GOOG 2019 9 26 1241.959961 1245.000000 1232.267944 NaN
186 GOOG 2019 9 27 1243.010010 1244.020020 1214.449951 NaN
187 GOOG 2019 9 30 1220.969971 1226.000000 1212.300049 1219.000000
188 GOOG 2019 10 1 1219.000000 1231.229980 1203.579956 1205.099976
189 GOOG 2019 10 2 1196.979980 1196.979980 1171.290039 1176.630005
190 GOOG 2019 10 3 1180.000000 1189.060059 1162.430054 1187.829956
191 GOOG 2019 10 4 1191.890015 1211.439941 1189.170044 1209.000000
192 GOOG 2019 10 7 1204.400024 1218.203979 1203.750000 1207.680054
193 GOOG 2019 10 8 1197.589966 1206.079956 1189.010010 1189.130005
194 GOOG 2019 10 9 1199.349976 1208.349976 1197.630005 1202.310059
195 GOOG 2019 10 10 1198.579956 1215.000000 1197.339966 1208.670044
196 GOOG 2019 10 11 1222.209961 1228.390015 1213.739990 1215.449951
197 GOOG 2019 10 14 1212.339966 1226.329956 1211.760010 1217.140015
198 GOOG 2019 10 15 1220.400024 1247.329956 1220.400024 1243.010010
199 GOOG 2019 10 16 1241.170044 1254.739990 1238.449951 1243.640015
200 GOOG 2019 10 17 1250.930054 1263.324951 1249.939941 NaN
201 GOOG 2019 10 18 1253.459961 1258.890015 1241.079956 1245.489990
202 GOOG 2019 10 21 1252.260010 1254.629028 1240.599976 NaN
203 GOOG 2019 10 22 1247.849976 1250.599976 1241.380005 1242.800049
204 GOOG 2019 10 23 1242.359985 1259.890015 1242.359985 1259.130005
205 GOOG 2019 10 24 1260.900024 1264.000000 1253.714966 1260.989990
206 GOOG 2019 10 25 NaN NaN NaN NaN
207 GOOG 2019 10 28 1275.449951 1299.310059 1272.540039 1290.000000
208 GOOG 2019 10 29 1276.229980 1281.589966 1257.212036 1262.619995
209 GOOG 2019 10 30 1252.969971 1269.359985 1252.000000 1261.290039
210 GOOG 2019 10 31 1261.280029 1267.670044 1250.843018 1260.109985

1971 rows × 8 columns

Representing data as time series:

  • To represent data as time series, first I would combine the year, month and day column of the data frame
  • Use the date column as the index of the data frame
  • Display the dataframe
In [20]:
#representing data as time series
google_df['Date'] = pd.to_datetime(google_df[['Year', 'Month', 'Day']])
#setting the data column as index
google_df.set_index('Date', inplace =True)
google_df.head()
Out[20]:
Stock Year Month Day Open High Low Close
Date
2012-01-03 GOOG 2012 1 3 325.250885 332.827484 324.966949 331.462585
2012-01-04 GOOG 2012 1 4 331.273315 333.873566 329.076538 332.892242
2012-01-05 GOOG 2012 1 5 329.828735 330.745300 326.889740 328.274536
2012-01-06 GOOG 2012 1 6 NaN NaN NaN NaN
2012-01-09 GOOG 2012 1 9 322.042908 322.291962 309.455078 310.067780

Exporting data to an appropriate format:

  • Exporting the pre procesed data into csv file
In [21]:
#Exporting the data to csv file
google_df.to_csv("Alphabet Inc. Stock.csv", index=True, encoding='utf8')
In [22]:
#Dropping the the unnecessary columns
google_df = google_df.drop(["Stock", "Year", "Month", "Day"], axis=1)
#Diplaying the data frame
google_df.head()
Out[22]:
Open High Low Close
Date
2012-01-03 325.250885 332.827484 324.966949 331.462585
2012-01-04 331.273315 333.873566 329.076538 332.892242
2012-01-05 329.828735 330.745300 326.889740 328.274536
2012-01-06 NaN NaN NaN NaN
2012-01-09 322.042908 322.291962 309.455078 310.067780

Handling missing values:

  • Using interpolate method in the pandas library, I filled in the missing values in the dataframe
In [23]:
#Using df.interpolate, we can fill in the missing values in the dataframe
google_df = google_df.interpolate()
#Check if there are still any missing values left
google_df.isnull().sum()
Out[23]:
Open     0
High     0
Low      0
Close    0
dtype: int64
In [24]:
#Rounding off the stock figures to make sure there is consistency in the data 
google_df = google_df.round(2)
google_df.head()
Out[24]:
Open High Low Close
Date
2012-01-03 325.25 332.83 324.97 331.46
2012-01-04 331.27 333.87 329.08 332.89
2012-01-05 329.83 330.75 326.89 328.27
2012-01-06 325.94 326.52 318.17 319.17
2012-01-09 322.04 322.29 309.46 310.07

Pre processing completed:

  • The data contains no null values i.e there are no values in the dataset such as "Not Available", "NaN or "NA"
  • All the values are not strings either
  • This indicates that there all the values are present in the dataset.

Task 3.1: Data Analysis: Summarising the cleaned dataset

Descriptive Statistics:

  • Displaying the descriptive statistics of the dataset
  • Using the cleaned dataset for further analysis and visualization
  • Grouping the data by year and taking mean of the values and displaying descriptive statistics

Calculating mean of stocks for each year:

  • This helps us understand net stock price for each year for easier visualization.
In [25]:
#Finding mean for each of the open, high, low and closing values of the stocks for each year
google_df_year = google_df.groupby(google_df.index.year).mean().round(2)
#Displaying the most recent years that is the ending rows of the dataframe
google_df_year.tail()
Out[25]:
Open High Low Close
Date
2015 601.99 607.42 596.09 601.98
2016 743.71 749.45 737.59 743.40
2017 921.27 927.01 915.39 921.95
2018 1113.42 1125.66 1100.71 1112.99
2019 1160.84 1171.05 1152.03 1162.36
  • Above shown is the mean of all the stock prices(open, high, low, close) of Alphabet Inc. grouped by Year.
  • We can see that the Average Stock Prices go up every year.
  • Also notice that there has been quite a huge increase in stock prices per share from mean value of 601 dollars per share in 2015 to 1162 dollars per share in 2019.
In [26]:
#Using the pandas dataframe and the decribe method we can see the descriptive statistics
print("Alphabet Inc. Stock Descriptive Stats:")
google_df.describe().round(2)
Alphabet Inc. Stock Descriptive Stats:
Out[26]:
Open High Low Close
count 1971.00 1971.00 1971.00 1971.00
mean 724.03 730.07 717.70 724.08
std 290.30 293.13 287.78 290.59
min 279.12 281.21 277.22 278.48
25% 514.72 517.90 510.75 514.16
50% 698.38 703.99 691.00 697.77
75% 1013.96 1027.12 996.64 1015.76
max 1276.23 1299.31 1272.54 1290.00
  • The above tables gives us the descriptive statistics of Alphabet Inc. stock market showing different statistics like mean, standard deviation, minimum and maximum values.
  • As we can notice that the mean prices of Alphabet stock has been around 724 dollars per share and the maximum value of the stock price has been 1290 dollars per share.

Task 3.2: Data Analysis: Visualizing Data

Characterising and Visualizing time series:

  • Using matplotlib, I visualized the time series in order to gain characterisitic insights on daily, monthly, quarterly and annual frequencies.
In [27]:
#Plotting visualization of time series to see change rate of stock price annually
google_df["2012":"2019"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['#3FC5F0', '#4DD599','#8F71FF', '#ff5d9e'])
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Annual Frequency)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the annual trend of stock prices for the company Alphabet Inc. from the year 2012-2019.
  • We notice that the overall trend of the closing stock prices is increasing
  • The trend has been strickly rising from the year 2015 onwards and it is also quite instresting to notice the pattern from 2018 to 2019 onwards, it has been a inverse head and shoulders pattern, which is showing the reversal of a downward trend, that is increase in stock prices following the yer 2019.
  • Let us visualize the 2018-19 in terms of a monthly frequency to gain more insights.
In [28]:
#Plotting visualizations of time series to see change rate of stock price monthly
google_df["2018-01":"2019-04"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['#3FC5F0', '#4DD599','#8F71FF', '#ff5d9e'])
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Monthly Frequency)')
#Labelling the axis
plt.xlabel("Month",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the monthly trend of stock prices for the company Alphabet Inc. from March 2018 to March 2019
  • We notice that the overall trend of the closing stock prices is seasonal affected by the chosen time period. We can see rise and falls in particular months.
  • We can see that from July 2018 there has been a steep rise in the stock prices and following the end of 2018, there has been a decreasing trend.
  • Following January 2019, there has been a strict increase
  • This is very similar to the Apple stock prices trend.
  • Let us visualize the quarter from December 2018 to February 2019 in terms of a quarterly frequency to gain more insights.
In [29]:
#Plotting visualization of time series to see change rate of stock price quarterly
google_df["2018-12":"2019-02"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 3, color = ['#3FC5F0', '#4DD599','#8F71FF', '#ff5d9e'])
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Quarterly Frequency)')
#Labelling the axis
plt.xlabel("Quarter",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the quaterly trend of stock prices for the company Alphabet Inc. from December 2018 to February 2019
  • We notice that the trend of the prices have been drecreasing nearing the end of 2018 and increasing after January 2019.
  • The interesting part is the sudden fall in the prices in the first few days of January 2019 and an increase following those dates. This is very similar to the Apple trend as we saw previously
  • The trend following February 2019 has been more or less constant.
  • Let us visualize the daily frequency from January 2019 to February 2019 to gain more insights.
In [30]:
#Plotting visualization of time series to see change rate of stock price daily
google_df["2019-01-01":"2019-02-01"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 3, color = ['#3FC5F0', '#4DD599','#8F71FF', '#ff5d9e'])
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Daily Frequency)')
#Labelling the axis
plt.xlabel("Day",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the daily trend of stock prices for the company Alphabet Inc. from January 2019 to February 2019
  • We notice that overall that has been an increasing trend for the stock prices for each day of the month.

Task 3.3: Quantifying and Discussing the time series

Discussing the changes in time series:

  • Using matplotlib, I used different graphs like bar graphs and rolling mean line graphs, I discussed the plots in details to get more insights.
In [31]:
#Plotting bar graph visualization of time series to see change rate of stock price annually
google_df_year.plot(kind = 'bar', figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, stacked = False, zorder=3,color = ['#3FC5F0', '#4DD599','#8F71FF', '#ff5d9e'] )
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Annual bar chart)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows that overall there has been a huge increase in the stock prices of Alphabet Inc. from around 350 dollars per share in the year 2012 to a massive 1190 dollars per share in the year 2019.
In [32]:
#Calculating 30 year rolling mean of ALPHABET INC. stock prices
rm = google_df["Close"].rolling(30).mean()
p = rm.plot(figsize=(16, 5), fontsize=13, grid = True, color= '#ff5d9e', linewidth = 3)
#Naming the plot
plt.title('Alphabet Inc. Stock Price (Rolling mean of 30 years)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13)
Out[32]:
Text(0, 0.5, 'Price($)')
  • The above plot shows the rolling mean line graph for the company Alphabet Inc.
  • Rolling means (or moving averages) are generally used to smooth out short-term fluctuations in time series data and highlight long-term trends.
  • We are now able to see a visualization which is without any noise.
  • Clearly we can notice that there was a slight fall in the stocks nearing 2019 which I would be discussing in detail in my outlying observations.

Task 3.4: Outlying observations & Final conclusions

Observations:

  • Through a candlestick plot made using plotly library, I discussed all the outlying observations throughout the changes in the time series.
In [33]:
#Using plotly library, plotting a candlestick graph to dicsuss the increasing and decreasing points of the stock prices
fig = go.Figure(data=[go.Candlestick(x=google_df.index,
                open=google_df['Open'],
                high=google_df['High'],
                low=google_df['Low'],
                close=google_df['Close'], increasing_line_color= '#4DD599', decreasing_line_color= '#ff5d9e')])
fig.update_layout(
    #Naming the plot
    title='Alphabet Inc. Stock Price',
    yaxis_title='Price($)',
    xaxis_title='Year',
    #Labelling the increasing and decreasing patterns
    shapes = [dict(
        x0='2017-01-09', x1='2017-01-09', y0=0, y1=1, xref='x', yref='paper',
        line_width=2)],
    annotations=[dict(
        x='2017-01-09', y=0.05, xref='x', yref='paper',
        showarrow=False, xanchor='left', text='Increase Period Begins')]
)
fig.show()

Reason for fall in 2018

  • According to maketwatch, The stock started its last bear market on Nov. 19, 2018, bottomed at a more than 14-month low of 984.67 dollars on Dec. 24, 2018, then ended the bear market on March 12, 2019 after rallying more than 20% off the bottom.
  • The world’s dominant provider of internet search, advertising, and video services, Alphabet has increased spending in recent years on areas including cloud computing and consumer electronics that it views as essential to maintaining its industry leadership. The disappointing earnings come as Google faces major challenges internally and from outside regulators.

2019: Rise

  • However, after the fall in stock prices in 2018, we can notice the stocks rising up in 2019 again.
  • Google, Alphabet's subsidiary is to benefit from digital ad revenue at an exponential rate, therefore analysts recomment in buying Alphabet's stock.
  • Google continues to grow its “other revenues” segment, which includes its cloud business and hardware sales. The division accounted for 6.49 billion dollars during the quarter, narrowly beating Wall Street estimates of 6.43 billion dollars.
  • That marks a 31 percent increase year over year. The company declined to break out Cloud revenues for the quarter, but said it remains “one of the fastest growing businesses across Alphabet.”

Disney

  • Stock analysis for the company Intel

Task 1: Data Collection

  • Using python, I downloaded the HTML pages for my chosen stocks
In [34]:
#calling the method get_raw_data to download data for the company DISNEY
get_raw_data("dis")

Task 2.1: Data Preparation: Parsing and extracting data

Parsing data:

  • Using pandas libray, I parsed and extracted the data for the company DISNEY and represented the whole dataset as a dataframe
In [35]:
#Creating the Disney dataframe and concatenting all the columns into one dataframe
disney_df = pd.read_html("http://mlg.ucd.ie/modules/COMP30760/stocks/dis.html")
disney_df = pd.concat(disney_df)
#Displaying the dataframe
disney_df
Out[35]:
Stock Year Month Day Open High Low Close
0 DIS 2012 1 3 37.970001 38.459999 37.939999 38.310001
1 DIS 2012 1 4 NaN NaN NaN NaN
2 DIS 2012 1 5 38.830002 39.580002 38.700001 39.500000
3 DIS 2012 1 6 39.549999 40.150002 39.450001 39.910000
4 DIS 2012 1 9 39.740002 40.250000 39.590000 39.750000
5 DIS 2012 1 10 39.480000 39.910000 39.160000 39.630001
6 DIS 2012 1 11 39.389999 39.529999 38.450001 38.700001
7 DIS 2012 1 12 38.619999 38.860001 38.410000 38.730000
8 DIS 2012 1 13 38.470001 38.590000 38.020000 38.400002
9 DIS 2012 1 17 38.689999 38.980000 38.410000 38.480000
10 DIS 2012 1 18 38.509998 39.099998 38.400002 39.020000
11 DIS 2012 1 19 39.009998 39.470001 39.000000 39.439999
12 DIS 2012 1 20 39.419998 39.439999 39.099998 39.310001
13 DIS 2012 1 23 39.380001 39.500000 38.959999 39.250000
14 DIS 2012 1 24 39.029999 39.270000 38.570000 39.250000
15 DIS 2012 1 25 39.119999 39.680000 38.959999 39.560001
16 DIS 2012 1 26 39.590000 39.750000 39.060001 39.349998
17 DIS 2012 1 27 39.270000 39.500000 38.980000 39.250000
18 DIS 2012 1 30 38.740002 39.110001 38.380001 38.990002
19 DIS 2012 1 31 39.080002 39.310001 38.660000 38.900002
20 DIS 2012 2 1 39.250000 39.669998 39.160000 39.330002
21 DIS 2012 2 2 39.220001 39.250000 38.560001 38.910000
22 DIS 2012 2 3 39.430000 40.000000 39.360001 40.000000
23 DIS 2012 2 6 40.000000 40.590000 39.959999 40.459999
24 DIS 2012 2 7 40.730000 41.150002 40.200001 40.980000
25 DIS 2012 2 8 41.369999 41.910000 40.990002 41.270000
26 DIS 2012 2 9 40.750000 41.639999 40.549999 41.529999
27 DIS 2012 2 10 40.939999 41.450001 40.830002 41.450001
28 DIS 2012 2 13 NaN NaN NaN NaN
29 DIS 2012 2 14 41.500000 41.619999 41.259998 41.599998
... ... ... ... ... ... ... ... ...
181 DIS 2019 9 20 133.029999 133.229996 131.610001 132.270004
182 DIS 2019 9 23 131.990005 132.889999 131.889999 132.460007
183 DIS 2019 9 24 134.009995 134.149994 131.500000 131.970001
184 DIS 2019 9 25 131.789993 133.419998 131.220001 133.089996
185 DIS 2019 9 26 133.139999 133.300003 129.059998 131.270004
186 DIS 2019 9 27 130.100006 131.000000 128.919998 129.960007
187 DIS 2019 9 30 130.350006 130.860001 129.820007 130.320007
188 DIS 2019 10 1 130.800003 131.779999 129.509995 129.550003
189 DIS 2019 10 2 128.509995 129.220001 127.570000 129.139999
190 DIS 2019 10 3 128.600006 129.429993 127.540001 NaN
191 DIS 2019 10 4 128.690002 130.440002 128.610001 130.270004
192 DIS 2019 10 7 130.270004 131.570007 129.039993 130.899994
193 DIS 2019 10 8 129.899994 130.039993 128.369995 128.470001
194 DIS 2019 10 9 129.100006 129.850006 128.059998 129.330002
195 DIS 2019 10 10 129.220001 130.139999 128.880005 129.339996
196 DIS 2019 10 11 130.300003 130.990005 129.839996 130.020004
197 DIS 2019 10 14 130.130005 130.300003 129.479996 129.699997
198 DIS 2019 10 15 130.009995 130.889999 129.399994 129.759995
199 DIS 2019 10 16 129.759995 131.830002 129.699997 130.860001
200 DIS 2019 10 17 132.529999 133.440002 130.509995 132.369995
201 DIS 2019 10 18 132.369995 133.160004 130.889999 NaN
202 DIS 2019 10 21 131.440002 131.729996 130.020004 130.259995
203 DIS 2019 10 22 133.149994 133.679993 132.100006 132.399994
204 DIS 2019 10 23 132.449997 132.679993 130.759995 131.130005
205 DIS 2019 10 24 131.520004 131.699997 129.630005 130.259995
206 DIS 2019 10 25 130.500000 131.759995 130.029999 130.899994
207 DIS 2019 10 28 131.449997 132.080002 130.139999 130.529999
208 DIS 2019 10 29 130.500000 130.770004 129.440002 NaN
209 DIS 2019 10 30 129.690002 130.309998 129.149994 129.600006
210 DIS 2019 10 31 129.529999 130.149994 128.750000 129.919998

1971 rows × 8 columns

Representing data as time series:

  • To represent data as time series, first I would combine the year, month and day column of the data frame
  • Use the date column as the index of the data frame
  • Display the dataframe
In [36]:
#representing data as time series
disney_df['Date'] = pd.to_datetime(disney_df[['Year', 'Month', 'Day']])
#setting the data column as index
disney_df.set_index('Date', inplace =True)
disney_df.head()
Out[36]:
Stock Year Month Day Open High Low Close
Date
2012-01-03 DIS 2012 1 3 37.970001 38.459999 37.939999 38.310001
2012-01-04 DIS 2012 1 4 NaN NaN NaN NaN
2012-01-05 DIS 2012 1 5 38.830002 39.580002 38.700001 39.500000
2012-01-06 DIS 2012 1 6 39.549999 40.150002 39.450001 39.910000
2012-01-09 DIS 2012 1 9 39.740002 40.250000 39.590000 39.750000

Exporting data to an appropriate format:

  • Exporting the data into csv file
In [37]:
#Exporting the dataframe to csv file
disney_df.to_csv("Disney Stock.csv", index=True, encoding='utf8')
In [38]:
#Dropping the the unnecessary columns
disney_df = disney_df.drop(["Stock", "Year", "Month", "Day"], axis=1)
#Diplaying the data frame
disney_df.head()
Out[38]:
Open High Low Close
Date
2012-01-03 37.970001 38.459999 37.939999 38.310001
2012-01-04 NaN NaN NaN NaN
2012-01-05 38.830002 39.580002 38.700001 39.500000
2012-01-06 39.549999 40.150002 39.450001 39.910000
2012-01-09 39.740002 40.250000 39.590000 39.750000

Handling missing values:

  • Using interpolate method in the pandas library, I filled in the missing values in the dataframe
In [39]:
#Using df.interpolate, we can fill in the missing values in the dataframe
disney_df = disney_df.interpolate()
#Check if there are still any missing values left
disney_df.isnull().sum()
Out[39]:
Open     0
High     0
Low      0
Close    0
dtype: int64
In [40]:
#Rounding off the stock figures to make sure there is consistency in the data 
disney_df = disney_df.round(2)
disney_df.head()
Out[40]:
Open High Low Close
Date
2012-01-03 37.97 38.46 37.94 38.31
2012-01-04 38.40 39.02 38.32 38.91
2012-01-05 38.83 39.58 38.70 39.50
2012-01-06 39.55 40.15 39.45 39.91
2012-01-09 39.74 40.25 39.59 39.75

Pre processing completed:

  • The data contains no null values i.e there are no values in the dataset such as "Not Available", "NaN or "NA"
  • All the values are not strings either
  • This indicates that there all the values are present in the dataset.

Task 3.1: Data Analysis: Summarising the cleaned dataset

Descriptive Statistics:

  • Displaying the descriptive statistics of the dataset
  • Using the cleaned dataset for further analysis and visualization
  • Grouping the data by year and taking mean of the values and displaying descriptive statistics

Calculating mean of stocks for each year:

  • This helps us understand net stock price for each year for easier visualization.
In [41]:
#Finding mean for each of the open, high, low and closing values of the stocks for each year
disney_df_year = disney_df.groupby(disney_df.index.year).mean().round(2)
#Displaying the most recent years that is the ending rows of the dataframe
disney_df_year.tail()
Out[41]:
Open High Low Close
Date
2015 107.91 108.66 106.95 107.82
2016 97.41 98.10 96.74 97.46
2017 106.36 106.98 105.72 106.35
2018 108.46 109.35 107.46 108.38
2019 128.13 128.98 127.03 128.10
  • Above shown is the mean of all the stock prices(open, high, low, close) of Disney grouped by Year.
  • We can see that the Average Stock Prices go up every year but there was a slight decrese in the year 2016 after which there was a very slight increase as compared to Alphabet Inc. and Apple.
  • Overall the mean of the closing values of stock prices in 2019 have been higher than the previous years.
In [42]:
#Using the pandas dataframe and the decribe method we can see the descriptive statistics
print("Disney Stock Descriptive Stats:")
disney_df.describe().round(2)
Disney Stock Descriptive Stats:
Out[42]:
Open High Low Close
count 1971.00 1971.00 1971.00 1971.00
mean 92.04 92.69 91.33 92.04
std 25.64 25.79 25.41 25.60
min 37.97 38.46 37.94 38.31
25% 71.28 71.87 70.61 71.26
50% 98.97 99.66 98.28 98.91
75% 109.98 110.56 109.20 109.94
max 145.76 147.15 145.17 146.39
  • The above tables gives us the descriptive statistics of Disney stock market showing different statistics like mean, standard deviation, minimum and maximum values.
  • As we can notice that the mean prices of Disney stock has been around 92 dollars per share and the maximum value of the stock price has been 146 dollars per share.

Task 3.2: Data Analysis: Visualizing Data

Characterising and Visualizing time series:

  • Using matplotlib, I visualized the time series in order to gain characterisitic insights on daily, monthly, quarterly and annual frequencies.
In [43]:
#Plotting visualization of time series to see change rate of stock price annually
disney_df["2012":"2019"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['Green', 'Yellow','Red', 'Blue'])
#Naming the plot
plt.title('Disney Stock Price (Annual Frequency)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the annual trend of stock prices for the company Disney from the year 2012-2019.
  • We notice that the overall trend of the closing stock prices is increasing but the trend contains many cup and handles and several patterns.
  • The trend has been a steady increase until 2016 followed by a cup and handle pattern nearing 2016 and a inverse head and shoulders pattern nearing 2017.
  • We can also see that just like Apple and Alphabet, there is a similar fall in disney stock prices in 2019.
  • Let us visualize the 2018-19 in terms of a monthly frequency to gain more insights.
In [44]:
#Plotting visualizations of time series to see change rate of stock price monthly
disney_df["2018-01":"2019-04"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['Green', 'Yellow','Red', 'Blue'])
#Naming the plot
plt.title('Disney Stock Price (Monthly Frequency)')
#Labelling the axis
plt.xlabel("Month",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the monthly trend of stock prices for the company Disney from March 2018 to March 2019
  • We notice that the overall trend of the closing stock prices is seasonal affected by the chosen time period. We can see rise and falls in particular months.
  • We can see that the trend repeats itself in cup and handle fashion.
  • However, it is interesting to notice the strict increase from March 2019 which resulted in Disney stocks worth 140 dollars per share.
  • Let us visualize the quarter from December 2018 to February 2019 in terms of a quarterly frequency to gain more insights.
In [45]:
#Plotting visualizations of time series to see change rate of stock price quarterly
disney_df["2018-12":"2019-02"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['Green', 'Yellow','Red', 'Blue'])
#Naming the plot
plt.title('Disney Stock Price (Quarterly Frequency)')
#Labelling the axis
plt.xlabel("Quarter",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the quaterly trend of stock prices for the company Disney from December 2018 to February 2019
  • We notice that the trend of the prices have been drecreasing nearing the end of 2018 and increasing after January 2019.
  • The interesting part is the sudden fall in the prices in the first few days of January 2019 and an increase following those dates. This is very similar to the Apple and Alphabet trend as we saw previously
  • The trend following February 2019 has been more or less constant.
  • Let us visualize the daily frequency from January 2019 to February 2019 to gain more insights.
In [46]:
#Plotting visualizations of time series to see change rate of stock price quarterly
disney_df["2019-01-01":"2019-02-01"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['Green', 'Yellow','Red', 'Blue'])
#Naming the plot
plt.title('Disney Stock Price (Daily Frequency)')
#Labelling the axis
plt.xlabel("Day",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the daily trend of stock prices for the company Disney from January 2019 to February 2019
  • We notice that overall that has been an increasing trend for the stock prices followed by a slight decrease in trend nearing february and a spike on the 1st of February 2019.

Task 3.3: Quantifying and Discussing the time series

Discussing the changes in time series:

  • Using matplotlib, I used different graphs like bar graphs and rolling mean line graphs, I discussed the plots in details to get more insights.
In [47]:
#Plotting bar graph visualization of time series to see change rate of stock price annually
disney_df_year.plot(kind = 'bar', figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, stacked = False, zorder=3, color = ['Green', 'Yellow','Red', 'Blue'])
#Naming the plot
plt.title('Disney Stock Price (Annual bar chart)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows that overall there has been a huge increase in the stock prices of Disney from around 50 dollars per share in the year 2012 to a massive 130 dollars per share in the year 2019.
In [48]:
#Calculating 30 year rolling mean of DISNEY stock prices
rm = disney_df["Close"].rolling(30).mean()
p = rm.plot(figsize=(16, 5), fontsize=13, grid = True, color= 'Blue', linewidth = 3)
#Naming the plot
plt.title('Disney Stock Price (Rolling mean of 30 years)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13)
Out[48]:
Text(0, 0.5, 'Price($)')
  • The above plot shows the rolling mean line graph for the company Disney.
  • We can notice the cup and handle pattern and that there was a slight fall in the stocks nearing 2019 which I would be discussing in detail in my outlying observations.

Task 3.4: Outlying observations & Final conclusions

Observations:

  • Through a candlestick plot made using plotly library, I discussed all the outlying observations throughout the changes in the time series.
In [49]:
#Using plotly library, plotting a candlestick plot to discuss the increasing and decreasing points of the stock prices
fig = go.Figure(data=[go.Candlestick(x=disney_df.index,
                open=disney_df['Open'],
                high=disney_df['High'],
                low=disney_df['Low'],
                close=disney_df['Close'], increasing_line_color= 'blue', decreasing_line_color= 'red')])
fig.update_layout(
    #naming the plot
    title='Disney Stock Price',
    #labelling the axis
    yaxis_title='Price($)',
    xaxis_title='Year',
    shapes = [dict(
        #labelling the increasing period line
        x0='2016-11-09', x1='2016-11-09', y0=0, y1=1, xref='x', yref='paper',
        line_width=2)],
    annotations=[dict(
        x='2016-11-09', y=0.05, xref='x', yref='paper',
        showarrow=False, xanchor='left', text='Increase Period Begins')]
)
fig.show()

2018 December: Disney stocks fall to about 3.71%

  • According to equities.com fter a few months of stock market turbulence, Disney is down 11% from the multiyear highs it reached over the fall of 2018. It's not that Disney itself did anything to upset investors; on the contrary, the company is nearing the closure of its takeover of Twenty-First Century Fox.
  • Among the S&P 500’s biggest fallers on Monday December 24 was The Walt Disney Company. The stock experienced a 3.71% decline to 100.35 dollars with 7.13 million shares changing hands. The Walt Disney Company started at an opening price of 103.23 and hit a high of 103.90 and a low of 100.35. Ultimately, the stock took a hit and finished the day at 3.87 dollars per share.

The 2019 rise

  • In 2019, the Disney stocks noticed a spike.
  • The increase in Walt Disney stock price was primarily driven by an increase in revenue and margins, along with a sharp drop of 202 million in shares outstanding which has pushed up the earnings per share. However, this momentum was partially offset by a reduction of 10.9x in the P/E multiple during this period. Despite recent hiccups with respect to margins, as per Walt Disney Valuation by Trefis, we have a price estimate of 152 per share for DIS’ stock, higher than its current market price.
  • Key revenue drivers include parks, resorts and studio entertainment. Domestic revenue growth is driven by higher average ticket prices for theme park admissions and for cruise line sailings, increased food, beverage, and merchandise spending, and higher average daily hotel room rates, along with higher volume due to higher attendance and passenger cruise ship days. Studio Entertainment revenue is expected to grow at a faster rate in the near term, driven by higher theatrical distribution and TV/SVOD revenues, partially offset by continued pressure in home entertainment. Also, the acquisition of FOX and the kickstart of Disney plus played a vital role in increasing the revnue of company to a huge extent.

Microsoft

  • Stock analysis for the company Microsoft

Task 1: Data Collection

  • Using python, I downloaded the HTML pages for my chosen stocks
In [50]:
#calling the method get_raw_data to download data for the company MICROSOFT
get_raw_data("msft")

Task 2.1: Data Preparation: Parsing and extracting data

Parsing data:

  • Using pandas libray, I parsed and extracted the data for the company MICROSOFT and represented the whole dataset as a dataframe
In [51]:
#Creating the Microsoft dataframe and concatenting all the columns into one dataframe
microsoft_df = pd.read_html("http://mlg.ucd.ie/modules/COMP30760/stocks/msft.html")
microsoft_df = pd.concat(microsoft_df)
#Displaying the dataframe
microsoft_df
Out[51]:
Stock Year Month Day Open High Low Close
0 MSFT 2012 1 3 26.549999 26.959999 26.389999 26.770000
1 MSFT 2012 1 4 26.820000 27.469999 26.780001 27.400000
2 MSFT 2012 1 5 27.379999 27.730000 27.290001 27.680000
3 MSFT 2012 1 6 27.530001 28.190001 27.530001 28.110001
4 MSFT 2012 1 9 28.049999 28.100000 27.719999 27.740000
5 MSFT 2012 1 10 27.930000 28.150000 27.750000 27.840000
6 MSFT 2012 1 11 27.430000 27.980000 27.370001 27.719999
7 MSFT 2012 1 12 27.870001 28.020000 27.650000 28.000000
8 MSFT 2012 1 13 27.930000 28.250000 27.790001 28.250000
9 MSFT 2012 1 17 28.400000 28.650000 28.170000 28.260000
10 MSFT 2012 1 18 28.309999 28.400000 27.969999 28.230000
11 MSFT 2012 1 19 28.160000 28.440001 28.030001 28.120001
12 MSFT 2012 1 20 28.820000 29.740000 28.750000 29.709999
13 MSFT 2012 1 23 29.549999 29.950001 29.350000 29.730000
14 MSFT 2012 1 24 29.469999 29.570000 29.180000 29.340000
15 MSFT 2012 1 25 29.070000 29.650000 29.070000 29.559999
16 MSFT 2012 1 26 29.610001 29.700001 29.400000 29.500000
17 MSFT 2012 1 27 29.450001 29.530001 29.170000 29.230000
18 MSFT 2012 1 30 28.969999 29.620001 28.830000 29.610001
19 MSFT 2012 1 31 29.660000 29.700001 29.230000 29.530001
20 MSFT 2012 2 1 29.790001 30.049999 29.760000 29.889999
21 MSFT 2012 2 2 29.900000 30.170000 29.709999 29.950001
22 MSFT 2012 2 3 30.139999 30.400000 30.090000 30.240000
23 MSFT 2012 2 6 30.040001 30.219999 29.969999 30.200001
24 MSFT 2012 2 7 30.150000 30.490000 30.049999 30.350000
25 MSFT 2012 2 8 30.260000 30.670000 30.219999 30.660000
26 MSFT 2012 2 9 30.680000 30.799999 30.480000 30.770000
27 MSFT 2012 2 10 30.639999 30.799999 30.360001 30.500000
28 MSFT 2012 2 13 30.629999 30.770000 30.430000 30.580000
29 MSFT 2012 2 14 30.330000 30.459999 29.850000 NaN
... ... ... ... ... ... ... ... ...
181 MSFT 2019 9 20 141.009995 141.649994 138.250000 139.440002
182 MSFT 2019 9 23 139.229996 139.630005 138.440002 139.139999
183 MSFT 2019 9 24 140.360001 140.690002 136.880005 137.380005
184 MSFT 2019 9 25 137.500000 139.960007 136.029999 139.360001
185 MSFT 2019 9 26 139.440002 140.179993 138.440002 139.539993
186 MSFT 2019 9 27 140.149994 140.360001 136.649994 137.729996
187 MSFT 2019 9 30 138.050003 139.220001 137.779999 NaN
188 MSFT 2019 10 1 139.660004 140.250000 137.000000 137.070007
189 MSFT 2019 10 2 136.250000 136.369995 133.580002 134.649994
190 MSFT 2019 10 3 134.949997 136.750000 133.220001 136.279999
191 MSFT 2019 10 4 136.750000 138.250000 136.419998 138.119995
192 MSFT 2019 10 7 137.139999 138.179993 137.020004 137.119995
193 MSFT 2019 10 8 137.080002 137.759995 135.619995 135.669998
194 MSFT 2019 10 9 137.460007 138.699997 136.970001 138.240005
195 MSFT 2019 10 10 138.490005 139.669998 138.250000 139.100006
196 MSFT 2019 10 11 140.119995 141.029999 139.500000 139.679993
197 MSFT 2019 10 14 139.690002 140.289993 139.520004 139.550003
198 MSFT 2019 10 15 140.059998 141.789993 139.809998 141.570007
199 MSFT 2019 10 16 140.789993 140.990005 139.529999 140.410004
200 MSFT 2019 10 17 140.949997 141.419998 139.020004 139.690002
201 MSFT 2019 10 18 139.759995 140.000000 136.559998 137.410004
202 MSFT 2019 10 21 138.449997 138.500000 137.009995 138.429993
203 MSFT 2019 10 22 138.970001 140.009995 136.259995 136.369995
204 MSFT 2019 10 23 136.880005 137.449997 135.610001 137.240005
205 MSFT 2019 10 24 139.389999 140.419998 138.669998 139.940002
206 MSFT 2019 10 25 139.339996 141.139999 139.199997 140.729996
207 MSFT 2019 10 28 144.399994 145.669998 143.509995 144.190002
208 MSFT 2019 10 29 144.080002 144.500000 142.649994 142.830002
209 MSFT 2019 10 30 143.520004 145.000000 142.789993 144.610001
210 MSFT 2019 10 31 144.899994 144.929993 142.990005 143.369995

1971 rows × 8 columns

Representing data as time series:

  • To represent data as time series, first I would combine the year, month and day column of the data frame
  • Use the date column as the index of the data frame
  • Display the dataframe
In [52]:
#representing data as time series
microsoft_df['Date'] = pd.to_datetime(microsoft_df[['Year', 'Month', 'Day']])
#setting the data column as index
microsoft_df.set_index('Date', inplace =True)
microsoft_df.head()
Out[52]:
Stock Year Month Day Open High Low Close
Date
2012-01-03 MSFT 2012 1 3 26.549999 26.959999 26.389999 26.770000
2012-01-04 MSFT 2012 1 4 26.820000 27.469999 26.780001 27.400000
2012-01-05 MSFT 2012 1 5 27.379999 27.730000 27.290001 27.680000
2012-01-06 MSFT 2012 1 6 27.530001 28.190001 27.530001 28.110001
2012-01-09 MSFT 2012 1 9 28.049999 28.100000 27.719999 27.740000

Exporting data to an appropriate format:

  • Exporting the data into csv file
In [53]:
#Exporting the raw data to csv file with Date as index
microsoft_df.to_csv("Microsoft Stock.csv", index=True, encoding='utf8')
In [54]:
#Dropping the the unnecessary columns
microsoft_df = microsoft_df.drop(["Stock", "Year", "Month", "Day"], axis=1)
#Diplaying the data frame
microsoft_df.head()
Out[54]:
Open High Low Close
Date
2012-01-03 26.549999 26.959999 26.389999 26.770000
2012-01-04 26.820000 27.469999 26.780001 27.400000
2012-01-05 27.379999 27.730000 27.290001 27.680000
2012-01-06 27.530001 28.190001 27.530001 28.110001
2012-01-09 28.049999 28.100000 27.719999 27.740000

Handling missing values:

  • Using interpolate method in the pandas library, I filled in the missing values in the dataframe
In [55]:
#Using df.interpolate, we can fill in the missing values in the dataframe
microsoft_df = microsoft_df.interpolate()
#Check if there are still any missing values left
microsoft_df.isnull().sum()
Out[55]:
Open     0
High     0
Low      0
Close    0
dtype: int64
In [56]:
#Rounding off the stock figures to make sure there is consistency in the data 
microsoft_df = microsoft_df.round(2)
microsoft_df.head()
Out[56]:
Open High Low Close
Date
2012-01-03 26.55 26.96 26.39 26.77
2012-01-04 26.82 27.47 26.78 27.40
2012-01-05 27.38 27.73 27.29 27.68
2012-01-06 27.53 28.19 27.53 28.11
2012-01-09 28.05 28.10 27.72 27.74

Pre processing completed:

  • The data contains no null values i.e there are no values in the dataset such as "Not Available", "NaN or "NA"
  • All the values are not strings either
  • This indicates that there all the values are present in the dataset.

Task 3.1: Data Analysis: Summarising the cleaned dataset

Descriptive Statistics:

  • Displaying the descriptive statistics of the dataset
  • Using the cleaned dataset for further analysis and visualization
  • Grouping the data by year and taking mean of the values and displaying descriptive statistics

Calculating mean of stocks for each year:

  • This helps us understand net stock price for each year for easier visualization.
In [57]:
#Finding mean for each of the open, high, low and closing values of the stocks for each year
microsoft_df_year = microsoft_df.groupby(microsoft_df.index.year).mean().round(2)
#Displaying the most recent years that is the ending rows of the dataframe
microsoft_df_year.tail()
Out[57]:
Open High Low Close
Date
2015 46.66 47.14 46.26 46.71
2016 55.23 55.67 54.78 55.26
2017 71.95 72.38 71.49 71.98
2018 101.12 102.11 99.92 101.01
2019 126.31 127.23 125.22 126.30
  • Above shown is the mean of all the stock prices(open, high, low, close) of Microsoft grouped by Year.
  • We can see that the Average Stock Prices go up every year.
  • We can also notice that there has been quite a huge increase in stock prices per share from mean value of 46 dollars per share in 2015 to 126 dollars per share in 2019.
In [58]:
#Using the pandas dataframe and the decribe method we can see the descriptive statistics
print("Microsoft Stock Descriptive Stats:")
microsoft_df.describe().round(2)
Microsoft Stock Descriptive Stats:
Out[58]:
Open High Low Close
count 1971.00 1971.00 1971.00 1971.00
mean 61.95 62.45 61.40 61.95
std 31.91 32.15 31.59 31.88
min 26.38 26.63 26.26 26.37
25% 36.90 37.20 36.54 36.83
50% 50.60 51.14 50.13 50.61
75% 83.56 84.10 83.01 83.42
max 144.90 145.67 143.51 144.61
  • The above tables gives us the descriptive statistics of Microsoft stock market showing different statistics like mean, standard deviation, minimum and maximum values.
  • As we can notice that the mean prices of Microsoft stock has been around 61 dollars per share and the maximum value of the stock price has been 144 dollars per share.

Task 3.2: Data Analysis: Visualizing Data

Characterising and Visualizing time series:

  • Using matplotlib, I visualized the time series in order to gain characterisitic insights on daily, monthly, quarterly and annual frequencies.
In [59]:
#Plotting visualization of time series to see change rate of stock price annually
microsoft_df["2012":"2019"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['#ffba01', '#01a6f0','#f34f1c', '#7fbc00'])
#Naming the plot
plt.title('Microsoft Stock Price (Annual Frequency)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the annual trend of stock prices for the company Microsoft from the year 2012-2019.
  • We notice that the overall trend of the closing stock prices is increasing and it is interesting to observe the two cup pattern in the year 2015-16.
  • We can also see that just like all the other companies above the stock prices fall in nearing 2019 and then shoot up.
  • Let us visualize the 2018-19 in terms of a monthly frequency to gain more insights.
In [60]:
#Plotting visualization of time series to see change rate of stock price monthly
microsoft_df["2018-01":"2019-04"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['#ffba01', '#01a6f0','#f34f1c', '#7fbc00'])
#Naming the plot
plt.title('Microsoft Stock Price (Monthly Frequency)')
#Labelling the axis
plt.xlabel("Month",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the monthly trend of stock prices for the company Microsoft from March 2018 to March 2019
  • We notice that the overall trend of the closing stock prices is seasonal affected by the chosen time period. We can see rise and falls in particular months.
  • However, it is interesting to notice the strict increase from January 2019 which resulted in Microsoft stocks worth 130 dollars per share.
  • Let us visualize the quarter from December 2018 to February 2019 in terms of a quarterly frequency to gain more insights.
In [61]:
#Plotting visualizations of time series to see change rate of stock price quarterly
microsoft_df["2018-12":"2019-02"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2,color = ['#ffba01', '#01a6f0','#f34f1c', '#7fbc00'] )
#Naming the plot
plt.title('Microsoft Stock Price (Quarterly Frequency)')
#Labelling the axis
plt.xlabel("Quarter",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows the quaterly trend of stock prices for the company Microsoft from December 2018 to February 2019
  • We notice that the trend of the prices have been drecreasing nearing the end of 2018 and increasing after January 2019.
  • The interesting part is the sudden fall in the prices in the first few days of January 2019 and an increase following those dates. This is very similar to the Apple and Alphabet trend as we saw previously

  • The plot below shows a daily trend for the Microsoft stocks from January 2019 to February 2019 and we notice an increasing trend follows by a slight decrease nearing 1st of February.

In [62]:
#Plotting visualization of time series to see change rate of stock price daily
microsoft_df["2019-01-01":"2019-02-01"].plot(figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, color = ['#ffba01', '#01a6f0','#f34f1c', '#7fbc00'])
#Naming the plot
plt.title('Microsoft Stock Price (Daily Frequency)')
#Labelling the axis
plt.xlabel("Day",fontsize=13)
plt.ylabel("Price($)",fontsize=13);

Task 3.3: Quantifying and Discussing the time series

Discussing the changes in time series:

  • Using matplotlib, I used different graphs like bar graphs and rolling mean line graphs, I discussed the plots in details to get more insights.
In [63]:
#Plotting bar graph visualization of time series to see change rate of stock price annually
microsoft_df_year.plot(kind = 'bar', figsize=(16, 5), fontsize=13, grid= True, linewidth = 2, stacked = False, zorder=3,color = ['#ffba01', '#01a6f0','#f34f1c', '#7fbc00'] )
#Naming the plot
plt.title('Microsoft Stock Price (Annual bar chart)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13);
  • The plot above shows that overall there has been a huge increase in the stock prices of Microsoft from around 30 dollars per share in the year 2012 to a massive 125 dollars per share in the year 2019.
In [64]:
#Calculating 30 year rolling mean of MICROSOFT stock prices
rm = microsoft_df["Close"].rolling(30).mean()
p = rm.plot(figsize=(16, 5), fontsize=13, grid = True, color= '#7fbc00', linewidth = 3)
#Naming the plot
plt.title('Microsoft Stock Price (Rolling mean of 30 years)')
#Labelling the axis
plt.xlabel("Year",fontsize=13)
plt.ylabel("Price($)",fontsize=13)
Out[64]:
Text(0, 0.5, 'Price($)')
  • The above plot shows the rolling mean line graph for the company Microsoft.
  • We can notice the strict increse and that there was a slight fall in the stocks nearing 2019 which I would be discussing in detail in my outlying observations.

Task 3.4: Outlying observations & Final conclusions

Observations:

  • Through a candlestick plot made using plotly library, I discussed all the outlying observations throughout the changes in the time series.
In [65]:
#Using plotly library, plotting a candlestick plot to discuss the increasing and decreasing points of the stock prices
fig = go.Figure(data=[go.Candlestick(x=microsoft_df.index,
                open=microsoft_df['Open'],
                high=microsoft_df['High'],
                low=microsoft_df['Low'],
                close=microsoft_df['Close'], increasing_line_color= '#f34f1c', decreasing_line_color= '#7fbc00')])
fig.update_layout(
    #naming the plot
    title='Microsoft Stock Price',
    #labelling the axis
    yaxis_title='Price($)',
    xaxis_title='Year',
    shapes = [dict(
        #labelling the increasing period line
        x0='2016-11-09', x1='2016-11-09', y0=0, y1=1, xref='x', yref='paper',
        line_width=2)],
    annotations=[dict(
        x='2016-11-09', y=0.05, xref='x', yref='paper',
        showarrow=False, xanchor='left', text='Increase Period Begins')]
)
fig.show()

Fall in stocks: December 2018

  • According to Bloomberg The Microsoft’s stock fell 11 percent in the three months ended in December, hitting a low point late in the year, as concerns emerged that tech spending was slowing, particularly in areas like PCs.

Reason for spike in 2019 January

  • Even with the market turmoil toward the end of the year, shares of Microsoft delivered an 18.7% return to shareholders last year, according to data provided by S&P Global Market Intelligence. The software giant continued to make advances in its transformation to a subscription and services-based business, which powered an impressive acceleration in revenue growth last year.
  • These results come as Microsoft is seeing impressive growth in its Azure cloud business, which grew 76% year over year in the fiscal first quarter ending in September. Microsoft is now the second largest cloud provider in the world. -Meanwhile, other areas of the company are performing well, too. The Productivity and Business Processes division grew revenue 19% in the fiscal first quarter, driven by growth in subscribers to Office 365, as well as a robust increase of 33% in revenue from LinkedIn.
  • The largest revenue contributor last quarter was the more personal computing segment, which grew 15% year over year, led by growth in Windows (up 12%), gaming (up 44%), search advertising (up 17%), and Surface devices (up 14%).
  • Overall, Microsoft is looking strong. Total revenue growth of 19% year over year in the first quarter of fiscal 2019 represented an acceleration over the year-ago quarter's 12% growth rate. Given the momentum, it's clear why the stock climbed 18% last year.

Task 3.5: Comparing the different time series

Observations:

  • Through a line plot made using plotly library, I compared the 4 time series and gave insights on my final conclusions.
In [66]:
#Using plotly library to display the comparison between all the 4 time series.
fig = go.Figure()
#Trend for the company Apple
fig.add_trace(go.Scatter(x=apple_df.index, y=apple_df['Close'], name="AAPL Close",
                         line_color='red'))

#Trend for the company Alphabet Inc.
fig.add_trace(go.Scatter(x=google_df.index, y=google_df['Close'], name="GOOG Close",
                         line_color='#ff5d9e'))

#Trend for the company Disney
fig.add_trace(go.Scatter(x=disney_df.index, y=disney_df['Close'], name="DIS Close",
                         line_color='Blue'))

#Trend for the company Microsoft
fig.add_trace(go.Scatter(x=microsoft_df.index, y=microsoft_df['Close'], name="MSFT Close",
                         line_color='#7fbc00'))

#Forming the plot layout
fig.update_layout(
    #Naming the plot
    title='Overall Stock Price of all 4 companies',
    #Naming the axis
    yaxis_title='Price($)',
    xaxis_title='Year',
    width = 1000,
    height = 500)
#Displaying the plot
fig.show()

Final Insights:

  • The above plot shows the 4 different time series and stock data from the companies Apple, Alphabet Inc., Disney, Microsoft
  • One of the first things I noticed is the vast difference between Alphabet Inc. stock prices and all the other companies. Alphabet Inc. has risen from aound 350 dollars per share of stock to 1200 and above which is a huge increase. We can aso see that Apple has performed well as well throughout the past few years.
  • One more similarity between all the time series has been the fall in stock prices nearing December 2018 and then the sudden rise in January 2019 followed by a reverse head and shoulders pattern on the plot and the mutual increasing period of stocks fetched from my candlestick plots has been around the year 2017.
  • 2018 was not a good year for the stock market. Since the beginning of the year, the Dow Jones Industrial Average has lost about 10 percent of its value, as did the S&P 500. The Nasdaq dropped roughly 8 percent.
  • The vast majority of losses have come since October, when the stock market, which was experiencing the longest bull run in history, took a turn for the worst. The stock market is on pace for its worst December since 1931, but it also setrecord single-day gains Wednesday, when the Dow jumped by more than 1,000 points.
  • The stock market woes come despite signs that the general economy is still doing well — with record low unemployment, strong GDP growth and relatively low inflation.
  • President Donald Trump’s trade war with China, the slowdown in global economic growth and concern that the Federal Reserve was raising interest rates too quickly all contributed to a pessimistic reaction from the stock market.

  • Stocks had their best January gains in more than 30 years, and that should mean 2019 will be a pretty good year for the market.

  • The market has sprung back from December’s low, with the S&P gaining 15 percent since Dec. 26. Stocks did well through most of January 2019, but by the end of the month, a correction started.
  • We can finally conclude that stocks are affected by a variety of reasons like US Trade War, valuations of the companies, revenue made by the company and the new products launched by the companies at different points of time.

Further Analysis:

  • We can make use machine learning algorithms and python libraries like stocker to predict the stock pattern for 2020 or even the following months.
  • This can make us get a better understanding of what to expect but then again since stock is affected by a lot of external factors, we cannot be 100% right.